from connector.DATAbaseDriver import DatabaseDriver


def get_type_id_by_cate_name(driver: DatabaseDriver, food_id: int):
    return driver.select_one(sql="select * from food where food_id='{}'".format(food_id), log=True)


def get_type_by_cate_name(driver: DatabaseDriver, food_id: str):
    return driver.select_one(sql="select * from food where food_id like '%{}%'".format(food_id), log=True)


def get_type(driver: DatabaseDriver) -> tuple:
    return driver.select_all("select * from food", log=True)

def delete_food(driver: DatabaseDriver, food_type: str) -> tuple:
    return driver.delete("delete from food where food_type={}".format(food_type))

def update_food(driver: DatabaseDriver, food_type: str) -> tuple:
    return driver.update("update food set food_type='{}'".format(food_type))


def get_type_by_id(driver: DatabaseDriver, cate_id: int) -> tuple:
    return driver.select_all("select * from type where type_id={}".format(cate_id), log=True)

def update_user(driver: DatabaseDriver, user_id: int, username: str, password: str, role: int):
    result: int = driver.update(
        'update user set user_name="{}", user_password="{}",user_role={} where '
        'user_id={}'.format(username, password, role, user_id))
    return result